﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AddressBook.DAO;
using AddressBook.Entity;
using System.Text;
public partial class GetNotifice : System.Web.UI.Page
{
    static NoticesDAO dao = new NoticesDAO();

    protected void Page_Load(object sender, EventArgs e)
    {
        ResultEntity result = new ResultEntity();
        result.Name = "Notifices";

        if (!string.IsNullOrEmpty(Request.QueryString["num"]) && !string.IsNullOrEmpty(Request.QueryString["phone"]))
        {
            DateTime updatetime = DateTime.Parse("1900-01-01");
            if (!string.IsNullOrEmpty(Request.QueryString["updatetime"]))
            {
                DateTime.TryParse(Request.QueryString["updatetime"], out updatetime);
            }

            List<Notices> lstNotify = dao.GetInfos(" top " + Request.QueryString["num"] + " Notices.* ", ",[Base_Employee] where Phone='" + Request.QueryString["phone"] + "' and PublishTime > '" + updatetime.ToString("yyyy-MM-dd HH:mm:ss") + "'  and PublishDeptID = LEFT([DeptID],LEN(PublishDeptID)) ", " order by PublishTime desc ", string.Empty);
            StringBuilder sb = new StringBuilder();

            foreach (Notices notify in lstNotify)
            {
                sb.Append("{");
                sb.AppendFormat("\"NoticeID\":\"{0}\",", notify.NoticeID);
                sb.AppendFormat("\"Title\":\"{0}\",", notify.Title.Replace("\"", ""));
                sb.AppendFormat("\"PublishTime\":\"{0}\"", notify.PublishTime);
                sb.Append("},");
            }
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }

            result.Desc = lstNotify.Count.ToString();//描述里返回条数
            result.Contents = sb.ToString();
            result.ResultCode = "0";
        }
        else
        {
            result.Desc = "参数不正确！";
            result.ResultCode = "-2";
        }
        Response.Write(Common.ReturnResult(result));
    }
}